package com.shangcheng.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shangcheng.dubbo.mappers.UmsResourceCategoryMapper;
import com.shangcheng.model.domain.UmsResourceCategory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author shiqiang
 * @version 1.0
 * @date 2022/5/13 18:00
 */
@DubboService
public class UmsResourceCategoryApiImpl implements UmsResourceCategoryApi{
    @Autowired
    private UmsResourceCategoryMapper resourceCategoryMapper;
    /**
     * 添加后台资源分类
     * @param umsResourceCategory
     */
    @Override
    public void createResourceCategory(UmsResourceCategory umsResourceCategory) {
        resourceCategoryMapper.insert(umsResourceCategory);
    }

    /**
     * 根据id删除后台资源分类
     * @param id
     */
    @Override
    public void deleteResourceCategory(Integer id) {
        resourceCategoryMapper.deleteById(id);
    }

    /**
     * 查询所有后台资源分类
     * @return
     */
    @Override
    public List<UmsResourceCategory> resourceCategoryList() {
        return resourceCategoryMapper.selectList(null);
    }

    /**
     * 修改后台资源分类
     * @param umsResourceCategory
     */
    @Override
    public void updateResourceCategory(UmsResourceCategory umsResourceCategory) {
        resourceCategoryMapper.updateById(umsResourceCategory);
    }

    /**
     * 根据名称查询分类
     * @param umsResourceCategory
     * @return
     */
    @Override
    public UmsResourceCategory findResourceCategoryByName(UmsResourceCategory umsResourceCategory) {
        LambdaQueryWrapper<UmsResourceCategory> wrapper= new LambdaQueryWrapper<>();
        wrapper.eq(UmsResourceCategory::getName,umsResourceCategory.getName());
        return resourceCategoryMapper.selectOne(wrapper);
    }

}
